// 88. 合并两个有序数组

/**
 Do not return anything, modify nums1 in-place instead.
 */
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
  const temp: number[] = new Array(n + m).fill(0);
  let one = 0;
  let two = 0;

  while (one < m || two < n) {
    // 数组一空
    if (one === m) {
      temp[one + two] = nums2[two++];
    } else if (two === n) {
      // 数组二排完
      temp[one + two] = nums1[one++];
    } else if (nums1[one] < nums2[two]) {
      //
      temp[one + two] = nums1[one++];
    } else {
      temp[one + two] = nums2[two++];
    }
  }
  console.log(temp);
  for (let i = 0; i !== m + n; i++) {
    nums1[i] = temp[i];
  }
}

const nums23 = [1, 2, 3, 0, 0, 0],
  m1 = 3,
  nums24 = [2, 5, 6],
  n1 = 3;
merge(nums23, m1, nums24, n1);
console.log(nums23);
